package design_pattern.singleton;

/**
 * @Name : singleton.SingleTon01
 * @Description : 描述
 * Created by cyd on 2021-02-02 11:40:03
 */
public class SingleTon01 {
    public static void main(String[] args) {
        // 测试，拿到的实例是同一个对象
        Singlton01 instance = Singlton01.getInstance();
        Singlton01 instance1 = Singlton01.getInstance();
        System.out.println(instance == instance1);
    }
}

class Singlton01 {
    // 1.私有化构造器
    private Singlton01() {
    }

    // 2.本例内部创建对象实例
    private final static Singlton01 INSTANCE = new Singlton01();

    // 3.提供一个共有的静态方法，返回这个实例对象
    public static Singlton01 getInstance() {
        return INSTANCE;
    }
}
